Skip to content

feat: add custom protoc-gen-zod plugin with buf.validate support#31

Merged
GuillaumeSachet merged 1 commit into
mainfrom
feat/protoc-gen-zod
Feb 4, 2026
Merged

feat: add custom protoc-gen-zod plugin with buf.validate support#31
GuillaumeSachet merged 1 commit into
mainfrom
feat/protoc-gen-zod

Conversation

@GuillaumeSachet
Copy link
Copy Markdown
Contributor

Add a custom Buf plugin that generates Zod schemas from proto definitions with automatic validation rules from buf.validate annotations.

Features:

  • Converts buf.validate constraints to Zod validations (.min(), .startsWith(), etc.)
  • Generates enum helper maps (ENUM_MAP and STRING_TO_ENUM)
  • Supports all scalar types, well-known types, and wrapper types
  • Handles recursive message types with z.lazy()
  • Skips empty files (no messages/enums)
  • Uses z.enum() instead of deprecated z.nativeEnum() for Zod v4

New files:

  • tools/zod/ - Custom protoc-gen-zod plugin source
  • .npmrc - Buf registry config for @buf/* dependencies

fix: change module type from ESNext to CommonJS in package.json and tsconfig.gen.json

feat(validation): enhance item-level constraints for repeated fields in Zod schemas

feat(validation): add support for int64/uint64 constraints in Zod validation chains

feat(validation): update file_id validation to use pattern matching for file identifiers

feat(validation): enhance validation handling for optional fields and string patterns in Zod schemas

fix(filesystem): regex in fileFilter prefix

fix(filesystem): allow 'default' as valid context in UploadFileData

Update the context field validation pattern to accept 'default' as a valid value in addition to the existing missions: and setups: prefixes.

chore: update devDependencies in package.json

  • Bump @bufbuild/buf from 1.61.0 to 1.64.0
  • Update @types/node from 25.0.3 to 25.2.0

fix(filesystem): enhance regex for prefix validation in FileFilter and UploadFileData

Updated the regex pattern for the 'prefix' field in FileFilter to prevent path traversal and ensure valid path formats. Additionally, added a pattern validation for the 'name' field in UploadFileData to enforce similar constraints.

fix(dependencies): update grpc-js, zod, and bufbuild packages to latest versions

Add a custom Buf plugin that generates Zod schemas from proto definitions
with automatic validation rules from buf.validate annotations.

Features:
- Converts buf.validate constraints to Zod validations (.min(), .startsWith(), etc.)
- Generates enum helper maps (ENUM_MAP and STRING_TO_ENUM)
- Supports all scalar types, well-known types, and wrapper types
- Handles recursive message types with z.lazy()
- Skips empty files (no messages/enums)
- Uses z.enum() instead of deprecated z.nativeEnum() for Zod v4

New files:
- tools/zod/ - Custom protoc-gen-zod plugin source
- .npmrc - Buf registry config for @buf/* dependencies

fix: change module type from ESNext to CommonJS in package.json and tsconfig.gen.json

feat(validation): enhance item-level constraints for repeated fields in Zod schemas

feat(validation): add support for int64/uint64 constraints in Zod validation chains

feat(validation): update file_id validation to use pattern matching for file identifiers

feat(validation): enhance validation handling for optional fields and string patterns in Zod schemas

fix(filesystem): regex in fileFilter prefix

fix(filesystem): allow 'default' as valid context in UploadFileData

Update the context field validation pattern to accept 'default' as a valid
value in addition to the existing missions: and setups: prefixes.

chore: update devDependencies in package.json

- Bump @bufbuild/buf from 1.61.0 to 1.64.0
- Update @types/node from 25.0.3 to 25.2.0

fix(filesystem): enhance regex for prefix validation in FileFilter and UploadFileData

Updated the regex pattern for the 'prefix' field in FileFilter to prevent path traversal and ensure valid path formats. Additionally, added a pattern validation for the 'name' field in UploadFileData to enforce similar constraints.

fix(dependencies): update grpc-js, zod, and bufbuild packages to latest versions
@GuillaumeSachet GuillaumeSachet merged commit 48ade47 into main Feb 4, 2026
1 check passed
@Relixik Relixik deleted the feat/protoc-gen-zod branch February 25, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants